
var http = require("http");
var express = require("express"); //引入express

var app = new express();

//跨域
app.all('*', function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
    res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');

    if (req.method == 'OPTIONS') {
        res.send(200); //让options请求快速返回
    } else {
        next();
    }
});

app.use('/static', express.static('public'));

var server = http.createServer(app);



app.get("/index", function (req, res, next) {
    res.sendFile(__dirname + "/views/index.html");
});



server.listen(8888, function () {
    console.log('服务端启动成功！端口8888! http://localhost:8888/index');
}); //express 监听 8080 端口，因为本机80端口已被暂用

